home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / emstools.arc / EMMLIB.ARC / EMM17_A.ASM < prev    next >
Assembly Source File  |  1990-02-04  |  13KB  |  191 lines

  1. ;-----------------------------------------------------------------------------;
  2. ;      MODULE NAME:   EMM17_A.ASM                                             ;
  3. ;                                                                             ;
  4. ;    FUNCTION NAME:   map_unmap_pages                                         ;
  5. ;                                                                             ;
  6. ;      DESCRIPTION:   This function can, in a single invocation, map (or      ;
  7. ;                     unmap) logical pages into as many physical pages as the ;
  8. ;                     system supports.  Consequently, it has less execution   ;
  9. ;                     overhead than mapping pages one at a time.  For         ;
  10. ;                     applications that do a lot of page mapping, this is     ;
  11. ;                     the preferred mapping method.                           ;
  12. ;                                                                             ;
  13. ;                     Mapping Multiple Pages:                                 ;
  14. ;                     The handle passed to this function determines what type ;
  15. ;                     of logical pages are being mapped.  Logical pages       ;
  16. ;                     allocated by the alloc_pages & alloc_std_pages functions;
  17. ;                     are referred to as pages, and are 16K bytes.  Logical   ;
  18. ;                     pages allocated by the alloc_raw_pages function are     ;
  19. ;                     referred to as raw pages, and might not be 16K bytes.   ;
  20. ;                                                                             ;
  21. ;                     Unmapping Multiple Pages:                               ;
  22. ;                     This function can make specific physical pages          ;
  23. ;                     unavailable for reading or writing.  A logical page     ;
  24. ;                     that is unmapped from a specific physical page can't    ;
  25. ;                     be read or written from that physical page.  The        ;
  26. ;                     unmapped logical page can be made available again       ;
  27. ;                     by mapping it or a new logical page at the physical     ;
  28. ;                     page that was unmapped.  (Unmap a physical page by      ;
  29. ;                     setting the logical page it is associated with to -1.   ;
  30. ;                                                                             ;
  31. ;                     For example, you might unmap an entire set of mapped    ;
  32. ;                     pages before loading and executing a program.  This     ;
  33. ;                     ensures that the loaded program won't be able to access ;
  34. ;                     the pages your program has mapped.  However, you must   ;
  35. ;                     save the mapping context before you unmap the physical  ;
  36. ;                     pages.  This enables you to restore it later and        ;
  37. ;                     access the memory you had mapped there.  You can save   ;
  38. ;                     or restore the mapping context with any of the EMMLIB   ;
  39. ;                     functions dedicated to doing so.                        ;
  40. ;                                                                             ;
  41. ;                     Mapping and Unmapping Multiple Pages Simultaneously:    ;
  42. ;                     Both mapping and unmapping pages can be done in the     ;
  43. ;                     same invocation.  Mapping or unmapping no pages is not  ;
  44. ;                     considered an error.  If a request to map or unmap zero ;
  45. ;                     pages is made, nothing is done and no error is          ;
  46. ;                     returned.                                               ;
  47. ;                                                                             ;
  48. ;                     Alternate Mapping and Unmapping Methods:                ;
  49. ;                     You can map or unmap pages using two methods.  Both     ;
  50. ;                     methods produce identical results.                      ;
  51. ;                     1. The first method specifies both a logical page and a ;
  52. ;                        physical page at which the logical page will be      ;
  53. ;                        mapped.  This method is an extension of the          ;
  54. ;                        map_page function.                                   ;
  55. ;                     2. The second method specifies both a logical page and  ;
  56. ;                        a corresponding segment address at which the logical ;
  57. ;                        page will be mapped.  (While this performs the same  ;
  58. ;                        function as the first method, it may be easier to    ;
  59. ;                        use the actual segment address of a physical page    ;
  60. ;                        than to use a number which only represents its       ;
  61. ;                        location.)  The memory manager checks whether the    ;
  62. ;                        specified segment address falls on the boundary of a ;
  63. ;                        mappable physical page.  The manager then translates ;
  64. ;                        the segment address passed to it into the necessary  ;
  65. ;                        internal representation to map the pages.            ;
  66. ;                                                                             ;
  67. ;           PASSED:   mode:                                                   ;
  68. ;                        is a flag that specifies whether the                 ;
  69. ;                        mu.phys_page_or_seg members in the mu array of       ;
  70. ;                        structures are physical pages or segment values.     ;
  71. ;                        A zero specifies that the mu.phys_page_or_seg        ;
  72. ;                        members are physical pages.  A one specifies that    ;
  73. ;                        the mu.phys_page_or_seg members are segments.        ;
  74. ;                                                                             ;
  75. ;                     mu_count:                                               ;
  76. ;                        is the number of entries in the mu array of          ;
  77. ;                        structures.  For example, if the array contained     ;
  78. ;                        four pages to map or unmap, then mu_count would be   ;
  79. ;                        four.  mu_count should not exceed the number of      ;
  80. ;                        mappable pages in the system.                        ;
  81. ;                                                                             ;
  82. ;                     mu:                                                     ;
  83. ;                        is a far pointer to an array of structures that      ;
  84. ;                        contains the information necessary to map the        ;
  85. ;                        desired pages.                                       ;
  86. ;                        The structure members are described here:            ;
  87. ;                                                                             ;
  88. ;                        mu.log_page:                                         ;
  89. ;                           is the number of the logical page to be mapped.   ;
  90. ;                           Logical pages are numbered relative to zero, so   ;
  91. ;                           the number for a logical page ranges from         ;
  92. ;                           zero to (maximum number of logical pages          ;
  93. ;                           allocated to the handle - 1).                     ;
  94. ;                                                                             ;
  95. ;                           If the logical page number is set to -1, the      ;
  96. ;                           physical page associated with it is unmapped      ;
  97. ;                           rather than mapped.  Unmapping a physical page    ;
  98. ;                           makes it inaccessible for reading or writing.     ;
  99. ;                                                                             ;
  100. ;                        mu.phys_page_or_seg:                                 ;
  101. ;                           is the physical page number or segment at which   ;
  102. ;                           the logical page is to be mapped.                 ;
  103. ;                                                                             ;
  104. ;                           Physical pages are numbered zero relative, so the ;
  105. ;                           number for a physical page can only range from    ;
  106. ;                           zero to (maximum number of physical pages         ;
  107. ;                           supported in the system - 1).                     ;
  108. ;                                                                             ;
  109. ;                           A segment address must correspond exactly to a    ;
  110. ;                           mappable segment address.  The mappable segment   ;
  111. ;                           addresses are available with the                  ;
  112. ;                           get_mappable_regions function.                    ;
  113. ;                                                                             ;
  114. ;                     handle:                                                 ;
  115. ;                        is an open EMM handle.                               ;
  116. ;                                                                             ;
  117. ;         RETURNED:   status:                                                 ;
  118. ;                        is the status EMM returns from the call.  All other  ;
  119. ;                        returned results are valid only if the status        ;
  120. ;                        returned is zero.  Otherwise they are undefined.     ;
  121. ;                                                                             ;
  122. ; C USE CONVENTION:   unsigned int status;                                    ;
  123. ;                     unsigned int mode;                                      ;
  124. ;                     unsigned int mu_count;                                  ;
  125. ;                     unsigned int handle;                                    ;
  126. ;                     MAP_STRUCT   mu[MAX_MAPPABLE_REGIONS];                  ;
  127. ;                                                                             ;
  128. ;                     mode                   = SEG_MODE;                      ;
  129. ;                     mu_count               = 2;                             ;
  130. ;                     mu[0].log_page         = 0;                             ;
  131. ;                     mu[0].phys_page_or_seg = 0xC000;                        ;
  132. ;                     mu[1].log_page         = 1;                             ;
  133. ;                     mu[1].phys_page_or_seg = 0xC400;                        ;
  134. ;                     status = map_unmap_pages (mode,                         ;
  135. ;                                               mu_count,                     ;
  136. ;                                               mu,                           ;
  137. ;                                               handle);                      ;
  138. ;-----------------------------------------------------------------------------;
  139. .XLIST
  140. PAGE    60,132
  141.  
  142. IFDEF SMALL
  143.    .MODEL SMALL, C
  144. ENDIF
  145. IFDEF MEDIUM
  146.    .MODEL MEDIUM, C
  147. ENDIF
  148. IFDEF LARGE
  149.    .MODEL LARGE, C
  150. ENDIF
  151. IFDEF COMPACT
  152.    .MODEL COMPACT, C
  153. ENDIF
  154. IFDEF HUGE
  155.    .MODEL HUGE, C
  156. ENDIF
  157.  
  158. INCLUDE emmlib.equ
  159. INCLUDE emmlib.str
  160. INCLUDE emmlib.mac
  161. .LIST
  162. .CODE
  163.  
  164. map_unmap_pages        PROC                                                  \
  165.             USES DS SI,                                           \
  166.             mode:BYTE,                                            \
  167.             map_unmap_struct_count:WORD,                          \
  168.             ptr_map_unmap_struct:FAR PTR BYTE,                        \
  169.             handle:WORD
  170.  
  171.     ;---------------------------------------------------------------------;
  172.     ;   do;                                                               ;
  173.     ;   .   map/unmap the list of mappable pages specified by the app;    ;
  174.     ;---------------------------------------------------------------------;
  175.     MOVE        AH, map_mult_page_fcn
  176.     MOVE        AL, mode
  177.     MOVE        DX, handle
  178.     MOVE        DS:SI, ptr_map_unmap_struct
  179.     MOVE        CX, map_unmap_struct_count
  180.     INT         EMM_int
  181.  
  182.     ;---------------------------------------------------------------------;
  183.     ;   .   return (EMM status);                                          ;
  184.     ;   end;                                                              ;
  185.     ;---------------------------------------------------------------------;
  186.     RET_EMM_STAT    AH
  187.  
  188. map_unmap_pages        ENDP
  189.  
  190. END
  191.